package yl.hs.bmipfull.service.system.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yl.hs.bmipfull.daos.system.IIconLocationDao;
import yl.hs.bmipfull.pojo.system.IconLocationEntity;
import yl.hs.bmipfull.service.system.IIconLocationService;
import yl.hs.bmipfull.utils.HsApp;
import yl.hs.bmipfull.viewmodels.system.IconLocationMondel;

import java.util.ArrayList;
import java.util.List;

/**
 * 作用:   <br/>
 * 创建时间: 2022-03-17 17:06 <br/>
 *
 * @author 吴高丰
 */
@Service
public class IconLocationServiceImpl extends SystemBaseService implements IIconLocationService {
    @Autowired
    IIconLocationDao dao;
    @Override
    public Integer insertNew(IconLocationEntity entity) {
        return dao.insertNew(entity);
    }

    @Override
    public Integer update(IconLocationEntity entity) {
        return dao.update(entity);
    }

    @Override
    public Integer deleteBySn(String userSN) {
        return dao.deleteBySn(userSN);
    }

    @Override
    public Integer save(List<IconLocationMondel> model) {
        try {
        var user = HsApp.getCurrent();
        dao.deleteBySn(user.getUserSN());
        List<IconLocationEntity> entityList = new ArrayList<>();
        model.forEach(t->{
            entityList.add(new IconLocationEntity(user.getUserSN(),t.getSn(),t.getX(),t.getY(),t.getW(),t.getH(),t.getY(),t.isVisible()));
        });
        dao.insertNew(entityList);
        }catch (Exception ee){
            return 0;
        }
        return 1;
    }
}
